package com.code.wanmi.controller;


import com.alibaba.fastjson.JSON;
import com.code.wanmi.entity.other.ResponseBean;
import com.code.wanmi.entity.wm_user.WmSysMenu;
import com.code.wanmi.service.IWmSysMenuService;
import com.code.wanmi.service.IWmSysRoleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author 谢晓峰
 * @since 2019-12-05
 */

@RestController
@RequestMapping("/menu")

public class WmSysMenuController {
    @Autowired
    private IWmSysMenuService iWmSysMenuService;
    @Autowired
    private IWmSysRoleService iWmSysRoleService;

    /**删除菜单权限通过ID*/
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public String deleteMenuById(@RequestParam("menu_id") long menu_id){
        Integer result=iWmSysMenuService.deleteRole(menu_id);
        return result>0?JSON.toJSONString(new ResponseBean(200,"success")):
                JSON.toJSONString(new ResponseBean(401,"fail"));
    }

    /**
     * 通过角色ID，查询角色权限。
     */
    @RequestMapping(value = "/find",method = RequestMethod.GET)
    public String getRoleByid(@RequestParam("role_id") long role_id){
        List<WmSysMenu> power= iWmSysRoleService.getRoleById(role_id);
        return JSON.toJSONString(new ResponseBean(200,"SUCCESS",power));
    }

    /**
     * 修改菜单权限信息
     * @param wmSysMenu
     * @return
     */
    @RequestMapping(value = "/updateMenu",method = RequestMethod.PUT)
    String updateMenu(@RequestBody WmSysMenu wmSysMenu) {
        return JSON.toJSONString(new ResponseBean(200,"SUCCESS",iWmSysRoleService.updateMenu(wmSysMenu)));
    }

}
